package org.fve.rtp;

import se.omnitor.protocol.rtp.RtpTextReceiver;
import se.omnitor.protocol.rtp.RtpTextTransmitter;
import se.omnitor.protocol.rtp.Session;
import se.omnitor.protocol.rtp.text.SyncBuffer;
import se.omnitor.util.FifoBuffer;

public class RTPText {
	/*private static String ipAddress ="172.26.0.80";
	private static String ipAddress2 ="172.26.0.84";
	private static int port =5555;
	private static int port2 =6666;*/
	private Session RtpSession;
	private RtpTextReceiver receiver;
	private RtpTextTransmitter transmitter;
	public static int T140PayloadType = 0x62;//98
	public static int RedPayloadType = 0x63;//99
	public static int localTextPort = 5000;
	//public static int remoteTextPort = 0;
	
	public RTPText(String my_ipAddress, String to_ipAddress , int to_port, int my_port){
		
		
		RtpSession = new Session(to_ipAddress, 64000, my_port);
		//Session RtpSession2 = new Session(ipAddress, 64000, port);
		
		FifoBuffer buffer = new FifoBuffer();
		
		//init the RTP listener
		receiver = new RtpTextReceiver(RtpSession, my_ipAddress, my_port, false, 96, 98, buffer);
		receiver.start();
		System.out.println("Receiver started.");
		
		SyncBuffer syncbuffer = new SyncBuffer(0, 300);
		//init the RTP Sender
		transmitter = new RtpTextTransmitter(RtpSession, true, to_ipAddress, my_port, to_port,96, false, 98, 0, false, 0, syncbuffer, false);
		transmitter.start();
		System.out.println("Transmitter started.");
		
		/*String hexCode="FF";
		
		transmitter.sendHexCode(hexCode);
		transmitter.sendHexCode(hexCode);
		transmitter.sendHexCode(hexCode);
		transmitter.sendHexCode(hexCode);*/		
		
		/*
		//enviar un paquete udp con java OK
		int i;
		byte[] buf = new byte[256];
		DatagramSocket socket;
		DatagramPacket packet;
		InetAddress address = InetAddress.getByName("172.26.0.84");
		System.out.println("address:"+address);
		for(i = 0; i <= 40; i++)
		{
		socket = new DatagramSocket(i);
		packet = new DatagramPacket(buf, buf.length, address, i);
		socket.send(packet);
		System.out.println("Enviado paquete"+packet);
		}*/
		
	}
	
	public Session GetRtpSession(){
		return RtpSession;
	}
	public RtpTextReceiver GetRtpTextReceiver(){
		return receiver;
	}
	
	public void SendHexCode(String hexCode){
		transmitter.sendHexCode(hexCode);
		System.out.println("RTPText-->SendHexCode: hexcode:"+hexCode);
	}

}
